package com.msconfig.device;

import com.geo.msconfig.R;
import com.msconfig.MyApplication;
import com.msconfig.bean.deviceInfoBean.TagDeviceInfo;

/*
* GETALL得到的每一行数据解析
*
* */
public class CommandParseManage {
    public TagDeviceInfo mDeviceInfo = new TagDeviceInfo();

    public TagDeviceInfo getDeviceInfo() {
        return mDeviceInfo;
    }

    // 单例模式获取实例
    private static CommandParseManage mCommandParseManage = null;

    public static CommandParseManage getInstance()
    {
        if (mCommandParseManage == null)
        {
            mCommandParseManage = new CommandParseManage();
        }

        return mCommandParseManage;
    }

    public boolean parseCommaneLine(String strCommandLine) {
        if (strCommandLine.length() == 0)
            return false;
        if (!strCommandLine.startsWith(MyApplication.getGlobalContext().getString(R.string.gnss_get_start_with))) {
            return false;
        }
        //@GNSS,GET,DEVICE.INFO.SERIAL,OK,M32018010013或者@GNSS,GET,DEVICE.INFO.SERIAL,OK,（value为空）
        if (strCommandLine.startsWith(MyApplication.getGlobalContext().getString(R.string.gnss_get_start_with))) {
            String[] sField = strCommandLine.split(",");
            boolean isOk=false;
            String value="";
            if(sField.length<4)
                return false;
            if(sField.length==4){//@GNSS,GET,DEVICE.INFO.SERIAL,OK,
                isOk=(sField[sField.length-1].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.is_ok)));
                value= "";
            }else if(sField.length==5){//@GNSS,GET,DEVICE.INFO.SERIAL,OK,M32018010013
                isOk=(sField[sField.length-2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.is_ok)));
                value= sField[sField.length-1];
            }
            if(!isOk)//不是ok
               return false;
            //设备信息
            if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_firmware_ver))) && isOk){
                mDeviceInfo.basicInfo.mFirmwareVersion=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_mcu_ver))) && isOk){
                mDeviceInfo.basicInfo.mMcuFirmwareVersion=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_power_level))) && isOk){
                mDeviceInfo.basicInfo.mBatteryLevel= MyApplication.getGlobalContext().getString(R.string.battery_level,value);
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_ext_voltage))) && isOk){
                mDeviceInfo.basicInfo.mBatteryVoltage= MyApplication.getGlobalContext().getString(R.string.battery_voltage,value);
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_disk_space))) && isOk) {
                if (value.equals(""))
                    return false;
                String[] storage = value.split("\\|");
                if (storage.length != 2)
                    return false;
                mDeviceInfo.basicInfo.mFreeStorage = storage[0];
                mDeviceInfo.basicInfo.mTotalStorageSpace = storage[1];

                //转换参数设置
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_gps_coordcvt_enabled))) && isOk){
                if(value.equals(MyApplication.getGlobalContext().getString(R.string.string_1))){
                    mDeviceInfo.transformInfo.mStartOutput=true;
                }else{
                    mDeviceInfo.transformInfo.mStartOutput=false;
                }
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_coordcvt_dst_datum))) && isOk){
                if(value.equals(""))
                    return false;
                String[] values=value.split("\\|");
                if(values.length!=3)
                    return false;
                mDeviceInfo.transformInfo.mEllipsoidName=values[0];
                mDeviceInfo.transformInfo.mEllipsoidLongHalfshaft=values[1];
                mDeviceInfo.transformInfo.mEllipsoidFlatteningInverse=values[2];
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_coordcvt_proj_param))) && isOk){
                if(value.equals(""))
                    return false;
                String[] values1 =value.split("\\|");
                String[] values = new String[]{"0","0","0","0","0","0","0","0","0","0"};
                for(int i=0;i<values1.length;i++){
                    values[i]=values1[i];
                }
                mDeviceInfo.transformInfo.mProjectionMode=values[0];
                mDeviceInfo.transformInfo.mCentralMeridian=values[1];
                mDeviceInfo.transformInfo.mProjectionScale=values[2];
                mDeviceInfo.transformInfo.mNorgaConstant=values[3];
                mDeviceInfo.transformInfo.mEastgaConstant=values[4];
                mDeviceInfo.transformInfo.mProjectionHeight=values[5];
                mDeviceInfo.transformInfo.mBaseLatitude=values[6];
                mDeviceInfo.transformInfo.mtBaseLogitude=values[7];
                mDeviceInfo.transformInfo.mParallel1=values[8];
                mDeviceInfo.transformInfo.mParallel2=values[9];




            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_gps_coordcvt_seven_param))) && isOk){
                if(value.equals(""))
                    return false;
                String[] values1 =value.split("\\|");
                String[] values = new String[]{"0","0","0","0","0","0","0","0"};
                for(int i=0;i<values1.length;i++){
                    values[i]=values1[i];
                }
                if(values[0].equals(MyApplication.getGlobalContext().getString(R.string.string_1))){
                    mDeviceInfo.transformInfo.mIsUseSevenParameter=true;
                }else{
                    mDeviceInfo.transformInfo.mIsUseSevenParameter=false;
                }

                mDeviceInfo.transformInfo.mSevenXTranslation=values[1];
                mDeviceInfo.transformInfo.mSevenYTranslation=values[2];
                mDeviceInfo.transformInfo.mSevenZTranslation=values[3];
                mDeviceInfo.transformInfo.mSevenXRotate=values[4];
                mDeviceInfo.transformInfo.mSevenYRotate=values[5];
                mDeviceInfo.transformInfo.mSevenZRotate=values[6];
                mDeviceInfo.transformInfo.mSevenScale=values[7];
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_gps_coordcvt_four_param))) && isOk){
                if(value.equals(""))
                    return false;
                String[] values1 =value.split("\\|");
                String[] values = new String[]{"0","0","0","0","0"};
                for(int i=0;i<values1.length;i++){
                    values[i]=values1[i];
                }
                if(values[0].equals(MyApplication.getGlobalContext().getString(R.string.string_1))){
                    mDeviceInfo.transformInfo.ismIsUseFourParameter=true;
                }else{
                    mDeviceInfo.transformInfo.ismIsUseFourParameter=false;
                }
                mDeviceInfo.transformInfo.mFourXTranslation=values[1];
                mDeviceInfo.transformInfo.mFourYTranslation=values[2];
                mDeviceInfo.transformInfo.mFourRotate=values[3];
                mDeviceInfo.transformInfo.mFourScale=values[4];
                //GPRS设置
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_network_enable))) && isOk){
                if(value.equals(MyApplication.getGlobalContext().getString(R.string.string_1))){
                    mDeviceInfo.gprsInfo.mIsStartNet=true;
                }else{
                    mDeviceInfo.gprsInfo.mIsStartNet=false;

                }
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_network_apn))) && isOk){
                mDeviceInfo.gprsInfo.mApn=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_network_apnuser))) && isOk){
                mDeviceInfo.gprsInfo.mApnUser=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_network_apnpass))) && isOk){
                mDeviceInfo.gprsInfo.mApnPass=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_device_sms_wakeup))) && isOk){
                if(value.equals(MyApplication.getGlobalContext().getString(R.string.string_1))){
                    mDeviceInfo.gprsInfo.mIsStartMessage=true;
                }else{
                    mDeviceInfo.gprsInfo.mIsStartMessage=false;
                }
                //wifi设置
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_device_wifi_mode))) && isOk){
                mDeviceInfo.wifiInfo.mWifiModel=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_device_wifi_ssid))) && isOk){
                mDeviceInfo.wifiInfo.mSsid=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_device_wifi_pass))) && isOk){
                mDeviceInfo.wifiInfo.mPassword=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_device_wifi_dhcp))) && isOk){
                if(value.equals(MyApplication.getGlobalContext().getString(R.string.string_1))){
                    mDeviceInfo.wifiInfo.mDHCP=true;
                }else{
                    mDeviceInfo.wifiInfo.mDHCP=false;
                }
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_wifi_ip))) && isOk){
                mDeviceInfo.wifiInfo.mIpAdress=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_wifi_mask))) && isOk){
                mDeviceInfo.wifiInfo.mSubnetLength=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_wifi_gateway))) && isOk){
                mDeviceInfo.wifiInfo.mDefaultGateway=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_wifi_dns1))) && isOk){
                mDeviceInfo.wifiInfo.mDns1=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_wifi_dns2))) && isOk){
                mDeviceInfo.wifiInfo.mDns2=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_wifi_band5g))) && isOk) {
                if (value.equals(MyApplication.getGlobalContext().getString(R.string.string_1))) {
                    mDeviceInfo.wifiInfo.mWifiBand= MyApplication.getGlobalContext().getString(R.string.band_5g);
                } else {
                    mDeviceInfo.wifiInfo.mWifiBand= MyApplication.getGlobalContext().getString(R.string.band_24g);
                }
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_wifi_prefix))) && isOk) {
                mDeviceInfo.wifiInfo.mPrefix=value;
            } else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_wifi_appass))) && isOk){
                mDeviceInfo.wifiInfo.mApPass=value;

                //测站设置
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_raw_name))) && isOk){
                mDeviceInfo.surveyInfo.mSurveyName=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_raw_interval))) && isOk){
                mDeviceInfo.surveyInfo.mRecordingInterval=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_cur_datalink))) && isOk){
                mDeviceInfo.surveyInfo.mDataLink=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_raw_ip))) && isOk){
                mDeviceInfo.surveyInfo.mFirstIp=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_raw_port))) && isOk){
                mDeviceInfo.surveyInfo.mFirstPort=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_raw_second_base))) && isOk){
                if(value.equals(MyApplication.getGlobalContext().getString(R.string.string_1))){
                    mDeviceInfo.surveyInfo.mIsDoubleStation=true;
                }else{
                    mDeviceInfo.surveyInfo.mIsDoubleStation=false;
                }
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_raw_result_status))) && isOk){
                mDeviceInfo.surveyInfo.mResultStatus=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_raw_result_ip))) && isOk){
                mDeviceInfo.surveyInfo.mResultIp=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_raw_result_port))) && isOk){
                mDeviceInfo.surveyInfo.mResultPort=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_raw_result_second_ip))) && isOk){
                mDeviceInfo.surveyInfo.mSecondIp=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_raw_result_result_port))) && isOk){
                mDeviceInfo.surveyInfo.mSecondPort=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_device_scheduled))) && isOk){//无
                mDeviceInfo.surveyInfo.mIsStartTiming=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_ext_sensor))) && isOk){
                if(value.equals(MyApplication.getGlobalContext().getString(R.string.string_1))){
                    mDeviceInfo.surveyInfo.mIsExternalSensor=true;
                }else{
                    mDeviceInfo.surveyInfo.mIsExternalSensor=false;
                }
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_dz_lot))) && isOk){
                if(value.equals(MyApplication.getGlobalContext().getString(R.string.string_1))){
                    mDeviceInfo.surveyInfo.mIsEarthDisaster=true;
                }else{
                    mDeviceInfo.surveyInfo.mIsEarthDisaster=false;
                }
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_raw_back))) && isOk){
                mDeviceInfo.surveyInfo.mCommunicationSetup=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_back_addr))) && isOk){
                mDeviceInfo.surveyInfo.mServerAdress=value;
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_back_port))) && isOk){
                mDeviceInfo.surveyInfo.mServerPort=value;

                //其他设置
            }else if((sField[2].equalsIgnoreCase(MyApplication.getGlobalContext().getString(R.string.command_zone))) && isOk) {
                mDeviceInfo.otherInfo.mTimeZone = value;
            }
            return true;
        }else{
            return false;
        }
    }

}
